/*
 * AnalogInputRelay.cpp
 *
 *  Created on: 2012. 10. 22.
 *      Author: dalxx
 */
#include <Arduino.h>
#include "AnalogInputRelay.h"

namespace PLCLib {


AnalogInputRelay::AnalogInputRelay(const char* _name, int _port, float Vref, float _rangeMin,
		float _rangeMax, int _rangeType) : Relay(_name) {
	this->port=_port;
	this->rangeMax=(1024*_rangeMax)/Vref;
	this->rangeMin=(1024*_rangeMin)/Vref;
	this->rangeType=_rangeType;
}

AnalogInputRelay::~AnalogInputRelay() {
	// TODO Auto-generated destructor stub
}

bool AnalogInputRelay::CalculateNext() {
	int an=analogRead(this->port);
	if(an>=this->rangeMin && an<=this->rangeMax)
	{
		return this->rangeType;
	}
	return !this->rangeType;



}

} /* namespace PLCLib */
